package cn.edu.ujs.coor.repository.relation;

import cn.edu.ujs.coor.model.ProjectUserRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProjectUserRelationRepository extends JpaRepository<ProjectUserRelation, String>, JpaSpecificationExecutor<ProjectUserRelation> {

    /**
     * 根据项目编号删除关联
     * @param projectId
     */
    void deleteByProjectId (String projectId);

    /**
     * 根据用户编号删除关联
     * @param userId
     */
    void deleteByUserId (String userId);

    /**
     * 查询关联用户编号
     * @param projectId
     * @return
     */
    @Query(value = "select user_id from coor_project_user where project_id = ?1", nativeQuery = true)
    List<String> findUserByProjectId (String projectId);
}
